<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
<h1>员工管理系统</h1>
  <div v-if="!isLogin">
    <a href="">注册</a>
    <!--javascript:void(0)废掉超链接的跳转功能-->
    <a href="javascript:void(0)" @click="login()">登录</a>
  </div>
  <div v-else>
    <input type="text" placeholder="员工姓名" v-model="newName">
    <input type="button" value="添加" @click="add()">
    <a href="javascript:void(0)" @click="logout()">退出登录</a>
  </div>
  <table border="1">
    <caption>员工列表</caption>
    <tr>
      <th>编号</th><th>名字</th><th v-if="isLogin">操作</th>
    </tr>
    <tr v-for="(name,i) in arr">
      <td>{{i+1}}</td>
      <td>{{name}}</td>
      <td v-if="isLogin"><input type="button" value="删除" @click="del(i)"></td>
    </tr>
  </table>
</div>
<!--从CDN服务器引入Vue框架文件-->
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
   let v=new Vue({
       el:"body>div",
       data:{
         isLogin:false,
         arr:["刘备","关羽","张飞"],
         newName:""
       },
       methods:{
         login(){
           v.isLogin=true;
         },
         logout(){
           v.isLogin=false;
         },
         add(){
           v.arr.push(v.newName);//往数组中添加员工名
         },
         del(i) {
           v.arr.splice(i,1);//从数组中删除员工名
         }
       }
   })
</script>
</body>
</html>